#include "scene.h"

#include "materials.h"
#include "primitives.h"

Scene::Scene()
{
}

Color Scene::trace(const Ray& r)
{
	// Nearest intersection to camera and its color
	float nearest = infinity;
	Color nearest_col;

	Vector3 hitpoint, normal;
	for(uint i = 0; i < objects.size(); ++i)
	{
		if(objects[i].primitive->intersect(r, hitpoint, normal))
		{
			float dist = (hitpoint - r.orig).length();
			if(dist < nearest)
			{
				nearest = dist;
				nearest_col = objects[i].material->shade(hitpoint, normal,
					r.orig);
			}
		}
	}

	return nearest_col;
}
